<?php
namespace core\tpl;


class TwigTpl extends BaseTpl  {
    private $_twig;

    public function __construct($tplDir, $cacheDir) {
        parent::__construct($tplDir);

        $loader = new \Twig\Loader\FilesystemLoader($tplDir);
        $this->_twig = new \Twig\Environment($loader, [
            'debug' => APP_DEBUG,
            'cache' => $cacheDir,
        ]);
    }

    public function import($tpl) {
        $filename = $tpl ?: CONTROLLER . '/' . METHOD . '.html';

        echo $this->_twig->render($filename, $this->_tplData);
    }
}
